home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Internet / WinHTTrack 3.41-2 / httrack-3.41-2.exe / {app} / src / htscore.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-08-15  |  12.5 KB  |  402 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: Main file .h                                           */
  34. /* Author: Xavier Roche                                         */
  35. /* ------------------------------------------------------------ */
  36.  
  37. // Fichier librairie .h
  38. #ifndef HTS_CORE_DEFH
  39. #define HTS_CORE_DEFH
  40.  
  41. #include "htsglobal.h"
  42.  
  43. /* specific definitions */
  44. #include "htsbase.h"
  45. // Includes & dΘfinitions
  46. #if ( defined(_WIN32) ||defined(HAVE_SYS_TYPES_H) )
  47. #include <sys/types.h>
  48. #endif
  49. #ifdef HAVE_SYS_STAT_H
  50. #include <sys/stat.h>
  51. #endif
  52. #ifdef _WIN32
  53. #ifndef  _WIN32_WCE
  54. #include <conio.h>
  55. #endif
  56. #ifndef  _WIN32_WCE
  57. #include <direct.h>
  58. #endif
  59. #else
  60. #ifdef HAVE_UNISTD_H
  61. #include <unistd.h>
  62. #endif
  63. #endif
  64. /* END specific definitions */
  65.  
  66. /* Forward definitions */
  67. #ifndef HTS_DEF_FWSTRUCT_lien_url
  68. #define HTS_DEF_FWSTRUCT_lien_url
  69. typedef struct lien_url lien_url;
  70. #endif
  71. #ifndef HTS_DEF_FWSTRUCT_lien_back
  72. #define HTS_DEF_FWSTRUCT_lien_back
  73. typedef struct lien_back lien_back;
  74. #endif
  75. #ifndef HTS_DEF_FWSTRUCT_struct_back
  76. #define HTS_DEF_FWSTRUCT_struct_back
  77. typedef struct struct_back struct_back;
  78. #endif
  79. #ifndef HTS_DEF_FWSTRUCT_cache_back
  80. #define HTS_DEF_FWSTRUCT_cache_back
  81. typedef struct cache_back cache_back;
  82. #endif
  83. #ifndef HTS_DEF_FWSTRUCT_hash_struct
  84. #define HTS_DEF_FWSTRUCT_hash_struct
  85. typedef struct hash_struct hash_struct;
  86. #endif
  87. #ifndef HTS_DEF_FWSTRUCT_filecreate_params
  88. #define HTS_DEF_FWSTRUCT_filecreate_params
  89. typedef struct filecreate_params filecreate_params;
  90. #endif
  91.  
  92. // Include htslib.h for all types
  93. #include "htslib.h"
  94.  
  95. // options
  96. #include "htsopt.h"
  97.  
  98. // INCLUDES .H PARTIES DE CODE HTTRACK
  99.  
  100. // routine main
  101. #include "htscoremain.h"
  102.  
  103. // core routines
  104. #include "htscore.h"
  105.  
  106. // divers outils pour httrack.c
  107. #include "htstools.h"
  108.  
  109. // aide pour la version en ligne de commande
  110. #include "htshelp.h"
  111.  
  112. // gΘnΘration du nom de fichier α sauver
  113. #include "htsname.h"
  114.  
  115. // gestion ftp
  116. #include "htsftp.h"
  117.  
  118. // gestion interception d'URL
  119. #include "htscatchurl.h"
  120.  
  121. // gestion robots.txt
  122. #include "htsrobots.h"
  123.  
  124. // routines d'acceptation de liens
  125. #include "htswizard.h"
  126.  
  127. // routines de regexp
  128. #include "htsfilters.h"
  129.  
  130. // gestion backing
  131. #include "htsback.h"
  132.  
  133. // gestion cache
  134. #include "htscache.h"
  135.  
  136. // gestion hashage
  137. #include "htshash.h"
  138. #include "htsinthash.h"
  139.  
  140. #include "htsdefines.h"
  141.  
  142. #include "hts-indextmpl.h"
  143.  
  144. // structure d'un lien
  145. #ifndef HTS_DEF_FWSTRUCT_lien_url
  146. #define HTS_DEF_FWSTRUCT_lien_url
  147. typedef struct lien_url lien_url;
  148. #endif
  149. struct lien_url {
  150.   char firstblock;      // flag 1=premier malloc 
  151.   char link_import;     // lien importΘ α la suite d'un moved - ne pas appliquer les rΦgles classiques up/down
  152.   int depth;            // profondeur autorisΘe lien ; >0 forte 0=faible
  153.   int pass2;            // traiter aprΦs les autres, seconde passe. si == -1, lien traitΘ en background
  154.   int premier;          // pointeur sur le premier lien qui a donnΘ lieu aux autres liens du domaine
  155.   int precedent;        // pointeur sur le lien qui a donnΘ lieu α ce lien prΘcis
  156.   //int moved;          // pointeur sur moved
  157.   int retry;            // nombre de retry restants
  158.   int testmode;         // mode test uniquement, envoyer juste un head!
  159.   char* adr;            // adresse
  160.   char* fil;            // nom du fichier distant
  161.   char* sav;            // nom α sauver sur disque (avec chemin Θventuel)
  162.   char* cod;            // chemin codebase Θventuel si classe java
  163.   char* former_adr;     // adresse initiale (avant Θventuel moved), peut Ωtre nulle
  164.   char* former_fil;     // nom du fichier distant initial (avant Θventuel moved), peut Ωtre nul
  165.   // pour optimisation:
  166.   int hash_next[3];     // prochain lien avec mΩme valeur hash
  167. };
  168.  
  169. // chargement de fichiers en 'arriΦre plan'
  170. #ifndef HTS_DEF_FWSTRUCT_lien_back
  171. #define HTS_DEF_FWSTRUCT_lien_back
  172. typedef struct lien_back lien_back;
  173. #endif
  174. struct lien_back {
  175. #if DEBUG_CHECKINT
  176.   char magic;
  177. #endif
  178.   char url_adr[HTS_URLMAXSIZE*2];     // adresse
  179.   char url_fil[HTS_URLMAXSIZE*2];     // nom du fichier distant
  180.   char url_sav[HTS_URLMAXSIZE*2];     // nom α sauver sur disque (avec chemin Θventuel)
  181.   char referer_adr[HTS_URLMAXSIZE*2]; // adresse host page referer
  182.   char referer_fil[HTS_URLMAXSIZE*2]; // fichier page referer
  183.   char location_buffer[HTS_URLMAXSIZE*2];  // "location" en cas de "moved" (302,..)
  184.   char* tmpfile;                           // nom α sauver temporairement (compressΘ)
  185.   char tmpfile_buffer[HTS_URLMAXSIZE*2];   // buffer pour le nom α sauver temporairement
  186.   char send_too[1024];    // donnΘes α envoyer en mΩme temps que le header
  187.   int status;             // status (-1=non utilisΘ, 0: prΩt, >0: opΘration en cours)
  188.   int locked;             // locked (to be used soon)
  189.   int testmode;           // mode de test
  190.   int timeout;            // gΘrer des timeouts? (!=0  : nombre de secondes)
  191.   TStamp timeout_refresh; // si oui, time refresh
  192.   int rateout;            // timeout refresh? (!=0 : taux minimum tolΘrΘ en octets/s)
  193.   TStamp rateout_time;    // si oui, date de dΘpart
  194.   LLint maxfile_nonhtml;  // taille max d'un fichier non html
  195.   LLint maxfile_html;     // idem pour un ficheir html
  196.   htsblk r;               // structure htsblk de chaque objet en background 
  197.   int is_update;          // mode update
  198.   int head_request;       // requΦte HEAD?
  199.   LLint range_req_size;   // range utilisΘ
  200.   TStamp ka_time_start;   // refresh time for KA 
  201.   //
  202.   int http11;             // L'en tΩte doit Ωtre signΘ HTTP/1.1 et non HTTP/1.0
  203.   int is_chunk;           // chunk?
  204.   char* chunk_adr;        // adresse chunk en cours de chargement
  205.   LLint chunk_size;       // taille chunk en cours de chargement
  206.   LLint chunk_blocksize;  // taille data declaree par le chunk
  207.   LLint compressed_size;  // taille compressΘs (stats uniquement)
  208.   //
  209.   //int links_index;        // to access liens[links_index]
  210.   //
  211.   char info[256];         // Θventuel status pour le ftp
  212.   int stop_ftp;           // flag stop pour ftp
  213.   int finalized;          // finalized (optim memory)
  214. #if DEBUG_CHECKINT
  215.   char magic2;
  216. #endif
  217. };
  218.  
  219. #ifndef HTS_DEF_FWSTRUCT_struct_back
  220. #define HTS_DEF_FWSTRUCT_struct_back
  221. typedef struct struct_back struct_back;
  222. #endif
  223. struct struct_back {
  224.   lien_back* lnk;
  225.   int count;
  226.   inthash ready;
  227.     LLint ready_size_bytes;
  228. };
  229.  
  230. typedef struct cache_back_zip_entry cache_back_zip_entry;
  231.  
  232. // cache
  233. #ifndef HTS_DEF_FWSTRUCT_cache_back
  234. #define HTS_DEF_FWSTRUCT_cache_back
  235. typedef struct cache_back cache_back;
  236. #endif
  237. struct cache_back {
  238.   int version;        // 0 ou 1
  239.   /* */
  240.   int type;
  241.   int ro;
  242.   FILE *dat,*ndx,*olddat;
  243.   char *use;      // liste des adr+fil
  244.   FILE *lst;      // liste des fichiers pour la "purge"
  245.   FILE *txt;      // liste des fichiers (info)
  246.   char lastmodified[256];
  247.   // HASH
  248.   inthash hashtable;
  249.   // HASH for tests (naming subsystem)
  250.   inthash cached_tests;
  251.   // fichiers log optionnels
  252.   FILE* log;
  253.   FILE* errlog;
  254.   // variables
  255.   int ptr_ant;      // pointeur pour anticiper
  256.   int ptr_last;     // pointeur pour anticiper
  257.   //
  258.   void *zipInput;
  259.   void *zipOutput;
  260.   cache_back_zip_entry* zipEntries;
  261.   int zipEntriesOffs;
  262.   int zipEntriesCapa;
  263. };
  264.  
  265. #ifndef HTS_DEF_FWSTRUCT_hash_struct
  266. #define HTS_DEF_FWSTRUCT_hash_struct
  267. typedef struct hash_struct hash_struct;
  268. #endif
  269. struct hash_struct {
  270.   lien_url** liens;                     // pointeur sur liens
  271.   int max_lien;                         // indice le plus grand rencontrΘ
  272.   int hash[3][HTS_HASH_SIZE];           // tables pour sav/adr-fil/former_adr-former_fil
  273. };
  274.  
  275. #ifndef HTS_DEF_FWSTRUCT_filecreate_params
  276. #define HTS_DEF_FWSTRUCT_filecreate_params
  277. typedef struct filecreate_params filecreate_params;
  278. #endif
  279. struct filecreate_params {
  280.   FILE* lst;
  281.   char path[HTS_URLMAXSIZE*2];
  282. };
  283.  
  284. /* Library internal definictions */
  285. #ifdef HTS_INTERNAL_BYTECODE
  286.  
  287. HTS_STATIC int cache_writable(cache_back* cache) {
  288.   return (cache != NULL && ( cache->dat != NULL || cache->zipOutput != NULL ) );
  289. }
  290.  
  291. HTS_STATIC int cache_readable(cache_back* cache) {
  292.   return (cache != NULL && ( cache->olddat != NULL || cache->zipInput != NULL ) );
  293. }
  294.  
  295. #endif
  296.  
  297. // Fonctions
  298.  
  299. // INCLUDES .H PARTIES DE CODE HTTRACK
  300.  
  301. /* Library internal definictions */
  302. #ifdef HTS_INTERNAL_BYTECODE
  303.  
  304. //
  305. #ifndef HTTRACK_DEFLIB
  306. HTSEXT_API int hts_is_parsing(httrackp *opt, int flag);
  307. HTSEXT_API int hts_is_testing(httrackp *opt);
  308. HTSEXT_API int hts_addurl(httrackp *opt, char** url);
  309. HTSEXT_API int hts_resetaddurl(httrackp *opt);
  310. HTSEXT_API int copy_htsopt(const httrackp* from,httrackp* to);
  311. HTSEXT_API char* hts_errmsg(httrackp *opt);
  312. HTSEXT_API int hts_setpause(httrackp *opt, int);
  313. //
  314. HTSEXT_API int hts_is_exiting(httrackp *opt);
  315. HTSEXT_API int hts_request_stop(httrackp* opt, int force);
  316. //
  317. HTSEXT_API int hts_cancel_file_push(httrackp *opt, const char *url);
  318. HTSEXT_API void hts_cancel_test(httrackp *opt);
  319. HTSEXT_API void hts_cancel_parsing(httrackp *opt);
  320. #endif
  321.  
  322. char* hts_cancel_file_pop(httrackp *opt);
  323.  
  324. #endif
  325.  
  326. //
  327.  
  328.  
  329. //int httpmirror(char* url,int level,httrackp opt);
  330. int httpmirror(char* url1,httrackp* opt);
  331. int filesave(httrackp* opt,const char* adr,int len,const char* s,const char* url_adr /* = NULL */,const char* url_fil /* = NULL */);
  332. char* hts_cancel_file_pop(httrackp *opt);
  333. int check_fatal_io_errno(void);
  334. int engine_stats(void);
  335. void host_ban(httrackp* opt,lien_url** liens,int ptr,int lien_tot,struct_back* sback,char* host);
  336. FILE* filecreate(filenote_strc *strct,const char* s);
  337. FILE* fileappend(filenote_strc *strct,const char* s);
  338. int filecreateempty(filenote_strc *strct, const char* filename);
  339. int filenote(filenote_strc *strct,const char* s,filecreate_params* params);
  340. void file_notify(httrackp* opt,const char* adr,const char* fil,const char* save,int create,int modify,int wasupdated);
  341. HTS_INLINE void usercommand(httrackp* opt,int exe,const char* cmd,const char* file,const char* adr,const char* fil);
  342. void usercommand_exe(const char* cmd,const char* file);
  343. int filters_init(char*** ptrfilters, int maxfilter, int filterinc);
  344. #ifndef HTTRACK_DEFLIB
  345. HTSEXT_API int structcheck(const char* path);
  346. HTSEXT_API int dir_exists(const char* path);
  347. #endif
  348. HTS_INLINE int fspc(httrackp *opt,FILE* fp,const char* type);
  349. char* next_token(char* p,int flag);
  350. //
  351. char* readfile(char* fil);
  352. char* readfile2(char* fil, LLint* size);
  353. char* readfile_or(char* fil,char* defaultdata);
  354. #if 0
  355. void check_rate(TStamp stat_timestart,int maxrate);
  356. #endif
  357.  
  358. // liens
  359. int liens_record(char* adr,char* fil,char* save,char* former_adr,char* former_fil,char* codebase);
  360.  
  361.  
  362. // backing, routines externes
  363. int back_pluggable_sockets(struct_back* sback, httrackp* opt);
  364. int back_pluggable_sockets_strict(struct_back* sback, httrackp* opt);
  365. int back_fill(struct_back* sback,httrackp* opt,cache_back* cache,lien_url** liens,int ptr,int numero_passe,int lien_tot);
  366. int backlinks_done(struct_back* sback,lien_url** liens,int lien_tot,int ptr);
  367. int back_fillmax(struct_back* sback,httrackp* opt,cache_back* cache,lien_url** liens,int ptr,int numero_passe,int lien_tot);
  368.  
  369. // cancel file
  370. #ifndef HTTRACK_DEFLIB
  371. HTSEXT_API int hts_cancel_file_push(httrackp *opt, const char *url);
  372. HTSEXT_API void hts_cancel_test(httrackp *opt);
  373. HTSEXT_API void hts_cancel_parsing(httrackp *opt);
  374. #endif
  375.  
  376. int ask_continue(httrackp *opt);
  377. int nombre_digit(int n);
  378.  
  379. // Java
  380. #if 0
  381. int hts_add_file(char* file,int file_position);
  382. #endif
  383.  
  384. // Polling
  385. #if HTS_POLL
  386. HTS_INLINE int check_flot(T_SOC s);
  387. HTS_INLINE int check_stdin(void);
  388. int read_stdin(char* s,int max);
  389. #endif
  390. HTS_INLINE int check_sockerror(T_SOC s);
  391. HTS_INLINE int check_sockdata(T_SOC s);
  392.  
  393. /* external modules */
  394. int htsAddLink(htsmoduleStruct* str, char* link);
  395.  
  396. // Void
  397. void voidf(void);
  398.  
  399. #define HTS_TOPINDEX "TOP_INDEX_HTTRACK"
  400.  
  401. #endif
  402.